{{ include("common/header.html")}}
<div class="admin">
    {{ include("common/nav.html")}}
    <script src="{{_G['APP']}}/resource/js/jquery-1.4.2.min.js"></script>
    <div class="aright">
        <div class="arz" style="float: left;margin: 0px 20px 20px 30px;"><a
                href="{{ G.url('admin/posts/postList')}}{{_G['APP_URL']}}?m=admin&c=posts&a=add"><i class="layui-icon">&#xe608;</i>添加帖子</a></div>

        <div style="float: left;">
            <form class="layui-form" action="{{ G.url('admin/posts/postList')}}" method="get">
                <input type="hidden" name="m" value="admin"/>
                <input type="hidden" name="c" value="posts"/>
                <input type="hidden" name="a" value="postList"/>
                <input placeholder="输入关键字" name="title" value="{{_GPC['title']}}"type="text" class="layui-input"
                       style="float: left;margin-right: 10px;width: 300px;">
                <button class="layui-btn" style="float: left;"  type="submit">查询</button>
            </form>
        </div>

        <form method="post" class="aform cl" id="form" action="{{ G.url('admin/posts/delete')}}">
            <table width="100%">
                <tr>
                    <th width="5%" align="center"><input type="checkbox" name="checkbox" id="selall"/></th>
                    <th width="5%" align="center">序号</th>
                    <th width="25%" align="center">帖子标题</th>
                    <!-- <th width="10%" align="center">缩略图</th>-->
                    <!-- <th width="10%" align="center">是否推荐</th>-->
                    <th width="9%" align="center">发布用户</th>
                    <th width="9%" align="center">所属分类</th>
                    <th width="9%" align="center">状态</th>
                    <th width="3%" align="center">置顶</th>
                    <th width="9%" align="center">创建时间</th>
                    <th width="9%" align="center">操作</th>
                </tr>

                {% for data in list %}
                <tr>
                    <td align="center"><input type="checkbox" class="selall" name="deletes[]" value="{{data.id}}"/></td>
                    <!--<td align="center">{{data.id}}</td>-->
                    <td align="center">{{loop.index}}</td>

                    <td align="center"><a style="color:#009688"href="{{ G.url('app/detail/index',{id:data.id})}}" target="_blank">{{data.title}}</a></td>
                    <td align="center">{{data.username}}</td>
                    <td align="center"><span style="color:#FF5722;">{{data.name}}</span></td>
                    <td align="center">
                        {% if data.status==0 %}
                        <span style="color:#FF5722;">未解决</span>
                        {% elseif data.status==1 %}
                        <span style="color:#0cb204;">已解决</span>
                        {% elseif data.status==2 %}
                        <span style="color:#1E9FFF;">精华</span>
                        {% else %}
                        <span style="color:#1e88e5;">黑名单</span>
                        {% endif %}
                    </td>
                    <td align="center">
                        {% if data.top == 0%}
                        <span>否</span>
                        {% else %}
                        <span style="color:#1e88e5;">是</span>
                        {% endif %}
                    </td>
                    <td align="center">{{data.create_time|date("Y-m-d H:i")}}</td>
                    <td align="center">
                        <a href="{{ G.url('admin/posts/edit',{id:data.id})}}"><i class="layui-icon"
                                                                                 style="font-size: 20px; color: #009688;">&#xe642;</i>
                            修改</a>
                        <a href="javascript:void(0)" onclick="del('{{ data.id }}');">
                            <i class="layui-icon" style="font-size: 20px; color: #009688;">&#xe640;</i>
                            删除
                        </a>
                    </td>
                </tr>
                {% endfor %}
            </table>
            <div class="layui-form-item">
                <div style="margin-top: 20px;">
                    <!--<button class="layui-btn" onclick="return confirm('您确定要删除吗？');" type="submit">删除选中</button>-->
                    <button class="layui-btn" lay-submit lay-filter="formDemo">删除选中</button>

                </div>
            </div>
        </form>
        <div class="pages">
            <div id="pages"></div>
        </div>
    </div>
</div>
<script>
    /**
     * 构造分页功能
     */
    layui.use('laypage', function () {
        var laypage = layui.laypage;

        //完整功能
        laypage.render({
            elem: 'pages',
            count: "{{pagination.total}}",
            limit: "{{pagination.page_size}}",
            curr: "{{pagination.current_page}}",
            layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
            jump: function (obj, first) {
                var url = "{{ G.url('admin/posts/postList',{'current_page':'currs','page_size':'limit'})}}";
                /**
                 * 替换处理
                 * @type {string}
                 */
                url = url.replace("currs", obj.curr);
                url = url.replace("limit", obj.limit);

                //首次不执行
                if (!first) window.location.href = escapeUrl(url);//转义amp字符

            }
        });

    });

    $("#selall").click(function () {

        if ($(this).attr("checked")) {
            $(".selall").attr("checked", "checked");
        } else {
            $(".selall").removeAttr("checked");
        }

    });

    layui.use('form', function () {
        var form = layui.form;
        var status = false;

        //监听提交
        form.on('submit(formDemo)', function () {
            console.log(123);

            if(status==false){
                layer.msg('您确定要删除吗？', {
                    time: 0,//不自动关闭
                    btn: ['确定', '取消'],
                    yes: function () {
                      status = true;
                        /**
                         * 再触发一次表单
                         */
                      $("#form").trigger('submit');

                    }
                });
            }else{
                return true;
            }
            return false;
        });

    });

    function del(id) {
        layui.use('layer', function () {
            var layer = layui.layer;
            //信息框-例2
            layer.msg('您确定要删除吗？', {
                time: 0,//不自动关闭
                btn: ['确定', '取消'],
                yes: function (index) {
                    var url = "{{ G.url('admin/posts/delete',{'id':'postsid'})}}";
                    url = url.replace("postsid", id);
                    window.location.href = escapeUrl(url);//转义amp字符
                }
            });
        });
    }
</script>
</body>
</html>